#include <stdio.h>
#include "fixed.h"

int main()
{
	double scale = 268435456.0; // 2^28

	double t1 = 5987243.10988;
	fixed_t t1i = fixed_from_double(t1);
	fixed_t t1o = fixed_log(t1i);

	printf("5987243.10988 <=> %lld <=> %.5f\n", t1i.val, fixed_to_double(t1i));
	printf("log(5987243.10988) <=> %lld <=> %.8f\n\n", t1o.val, fixed_to_double(t1o));

	float t2 = 0.39269909f;
	fixed_t t2i = fixed_from_float(t2);
	fixed_t t2s = FIXED_ZERO, t2c = FIXED_ZERO;
	fixed_sin_cos(t2i, &t2s, &t2c);
	
	printf("0.39269909 <=> %lld <=> %.8f\n", t2i.val, fixed_to_double(t2i));
	printf("sin(0.39269909) <=> %lld <=> %.8f\n", t2s.val, fixed_to_double(t2s));
	printf("cos(0.39269909) <=> %lld <=> %.8f\n\n", t2c.val, fixed_to_double(t2c));
	
	double t3 = 10.50;
	double t4 = -3.315;
	fixed_t t3i = fixed_from_double(t3);
	fixed_t t4i = fixed_from_double(t4);
	fixed_t t34o = fixed_mul(t3i, t4i);
	
	printf("10.5 <=> %lld <=> %.8f\n", t3i.val, fixed_to_double(t3i));
	printf("-3.315 <=> %lld <=> %.8f\n", t4i.val, fixed_to_double(t4i));
	printf("10.5 * -3.315 <=> %lld <=> %.8f\n\n", t34o.val, fixed_to_double(t34o));
	
	double t5 = 0.99736140;
	fixed_t t5i = fixed_from_double(t5);
	fixed_t t5o = fixed_sqrt(t5i);
	
	printf("0.99736140 <=> %lld <=> %.8f\n", t5i.val, fixed_to_double(t5i));
	printf("sqrt(0.99736140) <=> %lld <=> %.8f\n\n", t5o.val, fixed_to_double(t5o));
	
	fixed_t t7i = { 0x6fffffffffffffffLL };
	fixed_t t7o = fixed_sqrt(t7i);
	
	printf("sqrt(30064771071.99999999) simple <=> %lld <=> %.8f\n", t7o.val, fixed_to_double(t7o));
	printf("actual: 173391.95792193\n\n");
	
	const char *str1 = "3.14159";
	fixed_t t8 = fixed_from_string(str1);
	printf("3.14159 <=> %lld <=> %.8f\n", t8.val, fixed_to_double(t8));
	
	return 0;
}
